package com.xlcszsgc.core.util;

import java.io.InputStreamReader;
import java.util.Properties;

/**
 * @Title: PropertiesConfig.java
 * @Package com.dz51.core.utils
 * @Description: 读取Properties文件
 * @author Zhaoqt  
 * @date 2014-5-10 上午6:01:10
 * @version V1.0
 */
public class PropertiesConfig {
	
	private static Properties properties;
	private static String propertiesName = "defaultconfig.properties";
	/**
	 * 获取Properties
	 * @Title: getProperties
	 * @return
	 */
	public static Properties getProperties(String propertiesName) {
		InputStreamReader ins = null;
        try {  
        	if(propertiesName != null && !"".equals(propertiesName)) {
        		PropertiesConfig.propertiesName = propertiesName;
        	}
        	// 生成输入流  
    		ins = new InputStreamReader(
    				Thread.currentThread().getContextClassLoader ()
    				.getResourceAsStream(PropertiesConfig.propertiesName), "utf-8");
    		// 生成properties对象  
            properties = new Properties();  
        	properties.load(ins);  
        } catch (Exception e) {  
            e.printStackTrace();  
        } finally {
        	try {
				if(ins != null) {
					ins.close();
					ins = null;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
        }
        return properties;
	}
	
	public static String  getProperty(String key) {
		if( properties == null) {
			properties = getProperties(null);
		}
		return properties.getProperty(key);
	}
	
	public static String getProperty(String key, String propertiesName) {
		properties = getProperties(propertiesName);
		return properties.getProperty(key);
	}
}
